<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="100px">
      <el-form-item label="学校" prop="schoolName">
        <el-input v-model="queryParams.schoolName" readonly="readonly" @click.native="openSelectSchool(1)"
          placeholder="请输入学校" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="续费日期" prop="dateArray">
        <el-date-picker clearable type="daterange" format="yyyy-MM-dd" v-model="queryParams.dateArray"
          value-format="yyyy-MM-dd HH:mm:ss" :default-time="['00:00:00', '23:59:59']" placeholder="请选择签约日期">
        </el-date-picker>

      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-download" size="mini" @click="handleExport"
          v-hasPermi="['school:studentorder:report']">导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>
    <el-table v-loading="loading" :data="schoolinfoList">
      <el-table-column label="id" align="center" prop="id" />
      <el-table-column label="学校全称" align="center" prop="schoolName" />
      <el-table-column label="联系人" align="center" prop="contacts" />
      <el-table-column label="联系电话" align="center" prop="tel" />
      <el-table-column label="招生人数" align="center" prop="stuNum" />
      <el-table-column label="续费类型" align="center" prop="renewType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.stu_member_type" :value="scope.row.renewType" />
        </template>
      </el-table-column>

      <el-table-column align="center" label="新招">
        <el-table-column label="总人数" align="center" prop="addStuNum" />
        <el-table-column label="总佣金(元)" align="center" prop="addStuAmount" />
      </el-table-column>

      <el-table-column align="center" label="续费">
        <el-table-column label="总人数" align="center" prop="renewStuNum" />
        <el-table-column label="总佣金(元)" align="center" prop="renewStuAmount" />
      </el-table-column>

      <el-table-column label="总佣金(元)" align="center" prop="orderAmount" />
    </el-table>

    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />
    <!-- 选择校区 -->
    <SelectSchool ref="selectSchool" :open="selectFlag" @selected-data="selectSchoolData"
      @close-select-window="closeSelectSchool" />


  </div>
</template>

<script>
  import {
    orderSumList,
  } from "@/api/bus_web/report/school_report";
  import SelectSchool from "../school/schoolinfo/select.vue"
  import {
    isEmpty
  } from "@/utils/validate"
  import {
    isNumberStr
  } from '@/utils/index'
  import {
    mapState
  } from 'vuex';
  import store from "@/store";
  export default {
    name: "School_renew_order_report",
    dicts: ['stu_member_type'],
    components: {
      SelectSchool
    },
    data() {
      return {
        options: [],
        openTab: null,
        // 是否显示代理选择
        selectFlag: false,
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 学校管理表格数据
        schoolinfoList: [],
        // 弹出层标题
        title: "",
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          schoolIdList: [],
          schoolName: null,
          dateArray: []
        }
      };
    },
    created() {
      this.getList();
    },
    computed: {
      ...mapState({
        school: state => state.selectSchool.school,
        schoolSelectModel: state => state.selectSchool.schoolSelectModel,
      })
    },
    methods: {
      /** 查询学校管理列表 */
      getList() {
        this.loading = true

        if (this.queryParams.dateArray.length > 0) {
          this.queryParams.startTime = this.queryParams.dateArray[0]
          this.queryParams.endTime = this.queryParams.dateArray[1]
        }
        orderSumList(this.queryParams).then(response => {
          this.schoolinfoList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },

      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.queryParams.schoolIdList = []
        this.queryParams.startTime = null
        this.queryParams.endTime = null
        this.handleQuery();
      },
      //选择校区
      openSelectSchool(selectVal) {
        this.selectFlag = true
        // selectVal =1 查询模式 =2 创建、修改模式
        this.$store.dispatch('selectSchool/cleanSchool')
        this.$store.dispatch('selectSchool/setSchoolSelectModel', selectVal)
      },
      closeSelectSchool() {
        this.selectFlag = false
      },
      //确定校区
      selectSchoolData() {
        this.closeSelectSchool()
        if (this.schoolSelectModel == 2) {
          this.form.schoolName = this.school[0].schoolName
          this.form.schoolId = this.school[0].id
          this.$refs.form.clearValidate(['schoolName']);
        } else {
          this.queryParams.schoolName = this.school.map(item => item.schoolName).join(',')
          this.queryParams.schoolIdList = this.school.map(item => item.id)
        }
        this.$store.dispatch('selectSchool/cleanSchool')
      },

      /** 导出按钮操作 */
      handleExport() {
        this.download('school/studentorder/orderSumListExport', {
          ...this.queryParams
        }, `订单统计_${new Date().getTime()}.xlsx`)
      },
    }
  };
</script>

<style>
</style>
